<?php

App::uses('AppModel', 'Model');
App::uses('AuthComponent', 'Controller/Component');

/**
 * CoreUser Model
 *
 */
class CoreUser extends AppModel {

    /**
     * Validation rules
     *
     * @var array
     */
    public $validate = array(
        'cous_user' => array(
            'notempty' => array(
                'rule' => array('notempty'),
            //'message' => 'Your custom message here',
            //'allowEmpty' => false,
            //'required' => false,
            //'last' => false, // Stop validation after this rule
            //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
        'cous_password' => array(
            'notempty' => array(
                'rule' => array('notempty'),
            //'message' => 'Your custom message here',
            //'allowEmpty' => false,
            //'required' => false,
            //'last' => false, // Stop validation after this rule
            //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
    );

    public function beforeSave($options = array()) {
        if (isset($this->data[$this->alias]['cous_password'])) {
            $this->data[$this->alias]['cous_password'] = AuthComponent::password($this->data[$this->alias]['cous_password']);
        }
        return true;
    }
    
    public function beforeFind($queryData) {
        if (isset($queryData["conditions"]["CoreUser.cous_password"])) {
            $queryData["conditions"]["CoreUser.cous_password"] = AuthComponent::password($queryData["conditions"]["CoreUser.cous_password"]);
        }
        return $queryData;
    }
    
}
